home *** CD-ROM | disk | FTP | other *** search
- class CFreshSoundSystem
- {
- var m_masterSound;
- var m_arrSounds;
- var m_globalSoundHost;
- var m_panCenterX;
- var m_panWidthX;
- var m_isMuted = false;
- var m_masterVolume = 100;
- function CFreshSoundSystem(soundHost)
- {
- this.m_masterSound = new Sound();
- this.m_masterSound.setVolume(this.m_masterVolume);
- this.m_arrSounds = new Array();
- this.m_globalSoundHost = soundHost;
- _root.g_freshSoundSystem = this;
- }
- static function GetInstance()
- {
- return _root.g_freshSoundSystem;
- }
- function SetSpatialPanParameters(centerX, widthX)
- {
- this.m_panCenterX = centerX;
- this.m_panWidthX = widthX;
- }
- function SetMasterVolume(volume)
- {
- volume = MathUtil.Clamp(volume,0,100);
- this.m_masterVolume = volume;
- if(!this.m_isMuted)
- {
- this.m_masterSound.setVolume(this.m_masterVolume);
- }
- }
- function IsMuted()
- {
- return this.m_isMuted;
- }
- function SetMuted(muted)
- {
- this.m_isMuted = muted;
- if(this.m_isMuted)
- {
- this.m_masterSound.setVolume(0);
- }
- else
- {
- this.m_masterSound.setVolume(this.m_masterVolume);
- }
- }
- function GetHostedSoundId(soundId, hostMC)
- {
- return soundId + "~!~" + hostMC._name;
- }
- function PlaySound(soundId, hostMC, panX, nTimesToLoop, offsetSeconds)
- {
- FreshDebug.Assert(soundId != undefined && soundId.length > 0,"soundId");
- if(offsetSeconds == undefined)
- {
- offsetSeconds = 0;
- }
- var _loc2_ = this.m_arrSounds[soundId];
- if(!_loc2_)
- {
- var _loc4_ = undefined;
- if(this.m_globalSoundHost)
- {
- _loc4_ = this.m_globalSoundHost.createEmptyMovieClip("_soundHost" + this.m_globalSoundHost.getNextHighestDepth(),this.m_globalSoundHost.getNextHighestDepth());
- }
- _loc2_ = new Sound(_loc4_);
- _loc2_.attachSound(soundId);
- this.m_arrSounds[soundId] = _loc2_;
- }
- _loc2_.start(offsetSeconds,nTimesToLoop);
- if(panX)
- {
- this.SetSpatialPan(_loc2_,panX);
- }
- return _loc2_;
- }
- function SetSpatialPan(theSound, panX)
- {
- FreshDebug.Assert(theSound != undefined,"SetSpatialPan(): theSound != undefined");
- var _loc2_ = MathUtil.Clamp((panX - this.m_panCenterX) / this.m_panWidthX * 0.5 * 100,-100,100);
- theSound.setPan(_loc2_);
- }
- function StopSound(soundId, hostMC)
- {
- var _loc2_ = this.m_arrSounds[soundId];
- if(!_loc2_)
- {
- return undefined;
- }
- _loc2_.stop(soundId);
- }
- function StopAllSounds()
- {
- stopAllSounds();
- }
- }
-